package com.xlhj.boot.service.impl;

import com.xlhj.boot.service.TopicProducerService;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * @author: liucaijing
 * @description: TopicProducerServiceImpl
 * @date: 2021/10/20 9:02
 */
@Service
public class TopicProducerServiceImpl implements TopicProducerService {

    private static final String TOPIC_EXCHANGE_NAME = "topic-exchange";
    private static final String ROUTING_KEY_A = "topic.*.*";
    private static final String ROUTING_KEY_B = "*.*.rabbit";

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public void sendMessage(String message) {
        String uuid = UUID.randomUUID().toString();
        CorrelationData correlationData = new CorrelationData(uuid);
        rabbitTemplate.convertAndSend(TOPIC_EXCHANGE_NAME, ROUTING_KEY_A, message, correlationData);
    }
}
